package com.jy.wms.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.dao.StatisticsOfDistributionOfProvincesMapper;
import com.jy.wms.dao.WmsProvinceRankingReportMapper;
import com.jy.wms.pojo.WmsOrderDistribution;
import com.jy.wms.pojo.WmsOrderDistributionStatistics;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Service
public class StatisticsOfDistributionOfProvincesService extends BaseService<StatisticsOfDistributionOfProvincesMapper,WmsOrderDistribution> {


    /**
     * 各省订单分布统计（根据时间查询）
     *
     * @param
     * @return list
     */
    public JSONObject orderdistributionstatistics(WmsOrderDistribution WmsOrderDistribution, String hzid, String ckid) throws IOException {
        //将数据添加到map集合中
        JSONObject allJson = new JSONObject();
        Map<String, Object> zhh = new LinkedHashMap<>();

        Page<WmsOrderDistributionStatistics> order = null;
        String date = WmsOrderDistribution.getDate();

        if (date != null && date != "") {
            PageHelper.startPage(WmsOrderDistribution.getPage(), WmsOrderDistribution.getRows());
            order = (Page<WmsOrderDistributionStatistics>) dao.orderdistributionstatistics(date, hzid, ckid);
            JSONArray array = JSONArray.fromObject(order);
            allJson = SetStatus.setSearchType(array.toString(), (int) order.getTotal());
        }

        int a = 1;
        int ydsl = 0;//运单数量
        int fybh = 0;//订单量
        int xs = 0;//箱数
        int sjsl = 0;//支数
        int yf = 0;//运费
        int xse = 0;//销售额
        for (WmsOrderDistributionStatistics user : order) {
            if (user.getYdsl() != null && user.getYdsl() != "") {
                int YDSL = Integer.parseInt(user.getYdsl());
                ydsl += YDSL;
            }
            if (user.getFybh() != null && user.getFybh() != "") {
                int FYBH = Integer.parseInt(user.getFybh());
                fybh += FYBH;
            }
            if (user.getXs() != null && user.getXs() != "") {
                int XS = Integer.parseInt(user.getXs());
                xs += XS;
            }
            if (user.getSjsl() != null && user.getSjsl() != "") {
                int SJSL = Integer.parseInt(user.getSjsl());
                sjsl += SJSL;
            }
            if (user.getYf() != null && user.getYf() != "") {
                int YF = Integer.parseInt(user.getYf());
                yf += YF;
            }
            if (user.getXse() != null && user.getXse() != "") {
                int XSE = Integer.parseInt(user.getXse());
                xse += XSE;
            }
        }
        allJson.put("contentList", order);
        return allJson;
    }


    /**
     * 各省订单分布统计报表导出（根据时间查询）
     *
     * @param
     * @return list
     */

    public List<WmsOrderDistributionStatistics> baseSelectBathPrimaryKeys(WmsOrderDistributionStatistics WmsOrderDistributionStatistics, String hzid, String ckid) {
        //将数据添加到map集合中
        HashMap<Object, Object> map = new HashMap<Object, Object>();
        JSONObject allJson = new JSONObject();
        String date=WmsOrderDistributionStatistics.getDate();
        List<WmsOrderDistributionStatistics> order = null;

        int a = 1;
        int ydsl = 0;//运单数量
        int fybh = 0;//订单量
        int xs = 0;//箱数
        int sjsl = 0;//支数
        int yf = 0;//运费
        if (date != null && date != "") {
            order = dao.orderdistributionstatisticsExport(WmsOrderDistributionStatistics);
            for (WmsOrderDistributionStatistics user : order) {
                if (user.getYdsl() != null && user.getYdsl() != "") {
                    int YDSL = Integer.parseInt(user.getYdsl());
                    ydsl += YDSL;
                }
                if (user.getFybh() != null && user.getFybh() != "") {
                    int FYBH = Integer.parseInt(user.getFybh());
                    fybh += FYBH;
                }
                if (user.getXs() != null && user.getXs() != "") {
                    int XS = Integer.parseInt(user.getXs());
                    xs += XS;
                }
                if (user.getSjsl() != null && user.getSjsl() != "") {
                    int SJSL = Integer.parseInt(user.getSjsl());
                    sjsl += SJSL;
                }
                if (user.getYf() != null && user.getYf() != "") {
                    int YF = Integer.parseInt(user.getYf());
                    yf += YF;
                }
            }
        }
        return order;
    }
}
